import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class ArrayTest {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();

        // 添加元素，触发扩容
        for (int i = 0; i < 20; i++) {
            list.add(i);
            System.out.println("Size: " + list.size() + ", Capacity: " + getCapacity(list));
        }
    }

    // 获取 ArrayList 的容量（反射实现，仅用于演示）
    public static int getCapacity(ArrayList<?> list) {
        try {
            java.lang.reflect.Field field = ArrayList.class.getDeclaredField("elementData");
            field.setAccessible(true);
            return ((Object[]) field.get(list)).length;
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }
}
